﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Story.Framework.WinUI;
using Storys.Collect;
using DevExpress.XtraTreeList.Nodes;
using Storys.Collect.Entity;

namespace Storys.Collect.WinUI
{
    public partial class Sites : DockPanelBase
    {
        private SitesManager manSties = new SitesManager();
        public Sites()
        {
            InitializeComponent();
            this.Title = "猜猜猜";
            
        }
        public override void RefreData()
        {

            
            base.RefreData();
        }

        public override void SendMsageDo(string key, string msg)
        {
            if (key.Equals("Sites") && msg.Equals("Refresh"))
                LoadData();
        }

        private void Sites_Load(object sender, EventArgs e)
        {
           LoadData();
        }

        private void LoadData()
        {
            dsSite.SitesTable.Clear();
            dsSite.SitesTable.Merge(manSties.LoadSites());
            tlTask.BeginUnboundLoad();
            tlTask.Nodes.Clear();

            foreach (DataRow row in dsSite.SitesTable)
            {
                SiteDS.SitesTableRow sRow = row as SiteDS.SitesTableRow;
                TreeListNode node = tlTask.AppendNode(new object[] { sRow.fldName }, null);
                node.Tag = sRow.fldID;
            }
            tlTask.EndUnboundLoad();
        }

        private void BindTask()
        {

        }

        private void 修改网站ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AppClient.MainForm.ShowPage("Storys.Collect.WinUI.NewSitePage,Storys.Collect.WinUI");
            AppClient.SendMessageToPage("NewSitePage", tlTask.FocusedNode.Tag.ToString());
        }

        private void 删除网站ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dsSite.SitesTable.FindByfldID(Convert.ToInt32(tlTask.FocusedNode.Tag)).Delete();
            manSties.UpdateSite(dsSite.SitesTable);
            AppClient.SendMessageToPage("NewSitePage","-1");
            LoadData();
        }
    }
}
